;;; (Programming against the v1.38 interface of docker engine.)

(library (docker)
  (export)
  (import (rnrs base)
          (only (guile)
                lambda* λ
                display
                newline)
          (json)
          (container)
          (docker-socket)))


(define main
  (λ ()
    "entrypoint procedure"
    (call-with-output-docker-socket
     (λ (dock-sock)
       ;; (1) lists of multiple values for an argument are
       ;; expressed by vectors

       ;; (2) associations between a key and a values are
       ;; expressed as pairs, like in association lists

       ;; (3) the structure as a whole is expressed as an
       ;; association list

       ;; This is the representation format of guile-json.
       (define query-arguments-data
         '(("all" . "true")
           ("filters" . (("name" . #("db"))
                         ("status" . #("running" "exited"))))))

       (let ([resp-and-resp-text
              (/containers/json dock-sock #:data query-arguments-data)])
         (display resp-and-resp-text)
         (newline))))

    (call-with-output-docker-socket
     (λ (dock-sock)
       (let ([resp-and-resp-text
              (/containers/create dock-sock
                                  #:data '(("Image" . "ubuntu")
                                           ("Cmd" . #("date"))))])
         (display resp-and-resp-text)
         (newline))))))


(main)
